<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<%
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String url="jdbc:mysql://sqld.duapp.com:4050/ToszmXBSdefwbBRfZIAt";
String user="Ec2chH8MHnfQo9cUi0ga6jw9";
String password="tP94jTsaYQCj8XkRw8nb3QmmYAFp4OX0";

//String url="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8";
//String user="root";
//String password="niuxiao";

//String url="jdbc:mysql://312224.cicp.net:38833/test?useUnicode=true&amp;characterEncoding=utf-8";
//String user="root";
//String password="niufoxyyn123.";

Class.forName("com.mysql.jdbc.Driver");
//获得Connection对象
Connection DBConn = DriverManager.getConnection(url,user,password);
PreparedStatement ps=null;

Integer pageSize = 8;
String pageInt = request.getParameter("pageInt")==null?"1":request.getParameter("pageInt");
//Integer limitStr = pageSize*(Integer.parseInt(pageInt)-1);
//Integer limitEnd = pageSize*(Integer.parseInt(pageInt));
//Integer totalPage = 0;
//String sql = "select * from reservoir t limit "+limitStr+","+limitEnd;
String pondName = request.getParameter("pondName")==null?"":request.getParameter("pondName").trim();
pondName=java.net.URLDecoder.decode(new String(pondName), "utf-8");
String town = request.getParameter("town")==null?"":request.getParameter("town").trim();
town=java.net.URLDecoder.decode(new String(town), "utf-8");
String sql = "select id,pondName,town,townCode from pond where 1=1 ";
ResultSet rs = null;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta name="viewport"
	content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<html>
<head>
<base href="<%=basePath%>">
<title>奉化市重点海塘查询</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<link rel="stylesheet" href="css/easyui.css" type="text/css"></link>
<link rel="stylesheet" href="css/table.css" type="text/css"></link>
<meta http-equiv="expires" content="0">
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script>
	function sumbit(){
	
	    var name=document.getElementById("pondName").value;
	    var town=document.getElementById("town").value;
		document.getElementById("pondSerch").action="pond.jsp?pondName="+encodeURI(encodeURI(pondName))+"&town="+encodeURI(encodeURI(town));
		document.getElementById('pondSerch').submit();
	}
	function resetbutton(){
		$("#pondSerch input").val("");
		document.getElementById("town").value="";
		sumbit();
	}
	function turnPage(id){
		window.location.href="pondInfo.jsp?id="+id;
	}
	
		$(function(){
			var town = '<%=town%>' ;
			var select =  document.getElementById("town");
			if(town!=''){
				var varItem = new Option(town,town);
				select.options.add(varItem) ;
			}
			$.getJSON('json/townCode_date.json', function(data) {
			      $(data).each(function(i,ite){ 
			      		var varItem = new Option(ite.text,ite.id);
			      		select.options.add(varItem) 
			      })
		        });
			})
	</script>

</head>
<body>
	<form id="pondSerch">

		<div id="menubox">
			<ul>
				<li>海塘信息查询</li>
				<li>所属乡镇： <select id="town" name="town" onchange="sumbit();">
				</select>
				</li>
				<li>海塘名称：<input type="text" id="pondName" name="pondName"
					value="<%=pondName %>"></li>
				<li><button onclick="sumbit();">搜索</button>
					<button onclick="resetbutton();">清空</button>
				</li>
			</ul>
		</div>
		<div id="menubox1">
			<ul>
				<%
try {
	int i=0;
	if(pondName!=null && pondName!= ""&&!pondName.equals("null") && !pondName.equals("")){
		sql=sql+" and pondName like ?";
		i++;
	}
	if(town!=null && town!= ""&&!town.equals("null") && !town.equals("")){
			sql=sql+" and townCode like ?";
			i++;
	}
	sql+=" order by  townCode,pondLength desc";
	ps = DBConn.prepareStatement(sql);
	if(pondName!=null && pondName!= ""&&!pondName.equals("null") && !pondName.equals("")){
		ps.setString(1, "%"+pondName+"%");
	}
	if(town!=null && town!= ""&&!town.equals("null") && !town.equals("")){
		ps.setString(i, "%"+town+"%");
	}
	rs = ps.executeQuery();
	while(rs.next()){
%>
				<li onclick="turnPage('<%= rs.getString("id")%>');"><font>
						<a class="le"><%=rs.getString("pondName") %></a> <a class="ri"><%=rs.getString("townCode") %></a>
				</font></li>
				<%
	}	
} catch (SQLException e) {
	e.printStackTrace();
}finally {
	DBConn.close();
}
%>
			</ul>
		</div>
	</form>
</body>
</html>
